<?php
namespace app\api\validate;
use think\Validate;

class Brand extends Validate
{
    protected $rule = [
        'brand'         =>  'require',
        'product'       =>  'require|checkProduct',
        'team_video'    =>  'require|checkTeamVideo',
        'team_operate'  =>  'require|checkTeamOperate',
        'brandid'       =>  'require|number',
        'remark'        =>  'require',
        'productid'     =>  'require|number',
    ];

    protected $message = [
        'brand.require'         => '品牌名称不能为空!',
        'product.require'       => '品牌产品不能为空!',
        'team_video.require'    => '协同视频团队不能为空!',
        'team_operate.require'  => '协同运营团队不能为空!',
        'brandid.require'       => '品牌ID不能为空!',
        'brandid.number'        => '品牌ID类型错误!',
        'remark.require'        => '备注不能为空!',
        'productid.require'     => '产品ID不能为空!',
        'productid.number'      => '产品ID类型错误!',
    ];

    protected $scene = [
        'create'         =>  ['brand','product','team_video','team_operate'],
        'remark'         =>  ['brandid'],
        'delete'         =>  ['brandid'],
        'edit'           =>  ['brandid','brand','product','team_video','team_operate'],
        'check'          =>  ['productid'],
    ];
    
    protected function checkProduct($value,$rule,$data)
    {
        if(!is_array($value)){
            return '品牌产品参数格式错误!';
        }
        foreach ($value as $key => $value) {
            if(!is_array($value)){
                return '品牌产品参数格式错误!';
            }
            if(!isset($value['name']) || !isset($value['advertiser_id'])){
                return '品牌产品参数格式错误!';
            }
        }
        return true;
    }

    protected function checkTeamVideo($value,$rule,$data)
    {
        if(!is_array($value)){
            return '协同视频团队参数格式错误!';
        }
        return true;
    }

    protected function checkTeamOperate($value,$rule,$data)
    {
        if(!is_array($value)){
            return '协同运营团队参数格式错误!';
        }
        return true;    
    }
}